home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / gui4cli / ext / gui4cli.h < prev   
C/C++ Source or Header  |  1999-04-29  |  19KB  |  422 lines

  1. /*********************************************************************
  2. **
  3. **    Gui4Cli Include file
  4. **    $VER: 3.6 (20/8/98)
  5. **    Author : D. Keletsekis - dck@hol.gr
  6. **
  7. **    This file holds some of the Gui4Cli internal structures.
  8. **    You can access them by getting a pointer to the GCmain
  9. **    structure (see end of this file) and following the pointers
  10. **    from there.
  11. **
  12. **    The *GCmain pointer is stored in the "gcmain" field of the
  13. **    Gui4Cli message structure, and you can get it by sending 
  14. **    a GM_LOCK message to Gui4Cli, or when Gui4Cli sends you a
  15. **    message (using the CALL command).
  16. **
  17. **    From *GCmain you can see all the gui files, the events,
  18. **    the listviews, the variables, and most of everything that
  19. **    Gui4Cli holds dear. Why you would ever want to, is an 
  20. **    other matter.. Look at the C examples in this directory
  21. **    for information on how to access & manipulate them.
  22. **
  23. *********************************************************************/
  24.  
  25. // union used in events & commands, to hold the arguments, which
  26. // can be numbers or strings - LTWH=numbers, Title=string etc..
  27.  
  28. union commandunion
  29. {  LONG  num;    // if it's a number
  30.    char  *str;   // if it's a string
  31.    APTR  dummy;  // forget it..
  32. };
  33.  
  34. #define OPT_COUNT  12  // max number of arguments 
  35.  
  36. /*********************************************************************
  37.      The Gui4Cli message structure - use it to communicate with G4C
  38. *********************************************************************/
  39.  
  40. struct g4cmsg
  41. {
  42.    struct Message node;    // EXEC message structure
  43.  
  44.    // When Gui4Cli sends the message :
  45.    // - This will be a pointer to the command name which will
  46.    //   have been converted to upper case. If there are any more
  47.    //   arguments passed, then these will be stored in "args[0-5]"
  48.    // When you send a GM_COMMAND or GM_RUN message to Gui4Cli :
  49.    // - This must point to a string buffer which will contain
  50.    //   the command which you want Gui4Cli to execute.
  51.    // otherwise null..
  52.    UBYTE *com;
  53.  
  54.    // This will either contain a pointer to struct *GCmain, or 
  55.    // NULL. You get the pointer when Gui4Cli sends you a
  56.    // message (with the CALL command), or when Gui4Cli replies 
  57.    // to a GM_LOCK message that you sent. Otherwise NULL.
  58.    struct GCmain *gcmain;
  59.  
  60.    // Set this to 392001 which is a "magic" number that Gui4Cli
  61.    // will recognise as being a GC type message.
  62.    LONG  magic;
  63.  
  64.    // 6 argument strings. When Gui4Cli sends you a message, it
  65.    // will consist of a command (which will be in *com above)
  66.    // and up to 6 arguments. This is where the arguments will
  67.    // be stored (if any) - so, if arg[x] is not NULL, it will
  68.    // contain a pointer to a null terminated string.
  69.    UBYTE *args[6];
  70.  
  71.    // if you want to return something, then you must store it
  72.    // in a buffer which you MUST get using AllocVec() and point
  73.    // it here. The buffer will be available from within Gui4Cli
  74.    // as internal variable $$CALL.RET
  75.    // IMPORTANT NOTE:
  76.    // If you attach such a buffer, it will be freed by Gui4Cli, 
  77.    // using FreeVec(), before Gui4Cli sends it's next message.
  78.    UBYTE *msgret;
  79.  
  80.    UBYTE type;        // type of message - see defines below
  81.    LONG  res;        // error status (0 means OK)
  82.    APTR  data;        // null - for future expansion
  83.    APTR  exp;        // null - for future expansion
  84. };
  85.  
  86. /*********************************************************************
  87.      Message types
  88.      These are the currently available types for the "type" field 
  89.      of the above structure.
  90. *********************************************************************/
  91.  
  92. // ------------------------------------------------------------------
  93. // A)  If the command is sent by a program to Gui4Cli:
  94. //   The "com" field must point to a valid command line to be 
  95. //   executed by Gui4Cli - only commands which are defined as 
  96. //   "arexx capable" can be executed. The line will be translated,
  97. //   then parsed and executed. Upon returning, the "res"
  98. //   field will hold the return code, if any was set..
  99. // ---------------------- ...
  100. // B)  If sent by Gui4Cli to an outside program, using CALL :
  101. //   "com" will point to the command name, "gcmain" will contain
  102. //   a pointer to the GCmain structure, and if there are any arguments
  103. //   they will be stored in "args[0]"-"args[5]". Upon return, $$RetCode 
  104. //   will be set to the "res" value you have set (if any). 0 means OK
  105. // ------------------------------------------------------------------
  106. #define GM_COMMAND  1
  107.  
  108. // ------------------------------------------------------------------
  109. // This is the same as GM_COMMAND, Part (A). The difference is that 
  110. // while GM_COMMAND will do the commands synchronously - i.e. the 
  111. // program which sends the command will have to wait until after
  112. // Gui4Cli executes the command to receive the repply, GM_RUN will
  113. // pass the command to Gui4Cli and return and let Gui4Cli get on
  114. // with it asynchronously. The draw back is that you will not know
  115. // when the command finished executing and if it was successful.
  116. // ------------------------------------------------------------------
  117. #define GM_RUN      2
  118.  
  119. // ------------------------------------------------------------------
  120. // GM_LOCK will freeze Gui4Cli, until a GM_UNLOCK message is
  121. // received. When you send a GM_LOCK message, Gui4Cli will immediately
  122. // reply, storing a pointer to the "GCmain" structure in the message's
  123. // "gcmain" field. It will then wait, doing nothing until a GM_UNLOCK
  124. // message is received. Do what you want and then send GM_UNLOCK.
  125. // ------------------------------------------------------------------
  126. #define GM_LOCK        5
  127.  
  128. // ------------------------------------------------------------------
  129. // MUST UNLOCK Gui4Cli after a GM_LOCK message.
  130. // ------------------------------------------------------------------
  131. #define GM_UNLOCK   6
  132.  
  133. /*********************************************************************
  134.     LV helper structures
  135.     these hold various things for listviews..
  136. *********************************************************************/
  137.  
  138. // holds listview colors etc
  139.  
  140. struct styledef
  141. {
  142.    BOOL  usestyle;    // =1 if styles have been specifically set
  143.    WORD  fg;        // foreground pen
  144.    WORD  nbg;           // normal background pen
  145.    WORD  sbg;        // selected background pen
  146.    WORD  shad;        // shadow - signifies to make letters 3D
  147. };
  148.  
  149. // If a LV loads a DataBase file, it allocates a dbdef struct
  150. // and links it to the "db" member of the fulist struct. All
  151. // field definitions are link-listed to this struct.
  152.  
  153. struct lvfield              // field definition struct (AllocVec)
  154. {
  155.    char name[31];         // field name
  156.    LONG start;            // byte in record where field starts
  157.    LONG length;           // field length
  158.    UBYTE type;            // field type (N)umber,(C)har or (D)ate
  159.    struct styledef sd;  // full styledef struct
  160.    struct lvfield *next; // pointer to next field or null
  161.    // ----------- private fields below
  162. };
  163.  
  164. struct dbdef
  165. {
  166.    LONG fieldnum;        // number of fields
  167.    LONG reclength;        // record length
  168.    struct lvfield *topfield;    // linked list of fields (AllocVec)
  169.    // ------------- private fields below
  170. };
  171.  
  172. /*********************************************************************
  173.       LISTVIEW LINE
  174.       Every line of a listview has a structure like this.
  175.       They are kept in a struct List and given to the LV.
  176.       There is a pointer to this list in struct "fulist".
  177.       The LV shows the text pointed to by node->ln_Name.
  178.       This is set to point to some part of the *start buffer,
  179.       according to how much the list is shifted (left/right)
  180. **********************************************************************/
  181.  
  182. struct lister 
  183.   struct Node node;   // a normal exec node for struct List. The ln_Name
  184.                       // field points to the start of the visible text.
  185.   UBYTE *start;       // pointer to the start of the line's text - i.e. the full buffer
  186.   LONG  length;       // line length - buffer is AllocMem (length+1) !!!!
  187.   BOOL Selected;      // 1 = line is selected, 0 = it's not
  188.   struct fulist *fls; // ptr back to parent fulist structure (for hook)
  189.   UBYTE filend;       // pointer to end of filename - for dir listviews
  190.   UBYTE type;         // type of entry - F=file, D=dir etc
  191. };
  192.  
  193.  
  194. /*********************************************************************
  195.       LISTVIEW
  196.       This is the main listview structure holding all the information
  197.       needed for all the various types of listviews. A pointer to
  198.       this struct is kept in the EVENT structure of the xLISTVIEW event
  199. **********************************************************************/
  200.  
  201. struct fulist
  202. {
  203.   struct List *ls;         // the list structure with all the lines
  204.   int    maxlength;        // length of longest line (strlen)
  205.   int    maxnow;           // - not used any more
  206.   LONG   totnum;           // total number of lines
  207.   struct lister *curpt;    // pointer to current record (or null)
  208.   LONG   line;             // line number of current record (-1 if none)
  209.   UBYTE  maxdirlength;     // length of longest dir name (for size alignment)
  210.   char   curdir[140];      // buffer for current dir name (when in DIR mode)  
  211.   int    dirhook;          // gadid of xlvdirhook event or 0
  212.   struct Event *bt;        // point to the xLISTVIEW event
  213.   struct guifile *gf;      // points back to parent gui file
  214.   LONG   magic;            // sanity check - set to 22108
  215.   struct dbdef *db;       // link field info structure for database LVs 
  216.   struct styledef nsd;     // full styledef struct for normal records
  217.   struct styledef dsd;     // full styledef struct for dir,vol etc
  218.   SHORT  linedist;       // distance between lines
  219.  
  220.   // ----------- private fields below..
  221. };
  222.  
  223. /********************************************************************
  224.      IMAGES
  225.      structure used to hold image information
  226. *********************************************************************/
  227. struct imginfo 
  228. {  
  229.    Object                *po;      // the datatype object
  230.    struct BitMapHeader   *bmh;     // the header..
  231.    struct BitMap         *bm;      // the data..
  232.    char                  name[35]; // the name (alias) of this image
  233.    LONG                  count;    // times in use
  234.    struct imginfo        *next;    // next image
  235. };
  236.  
  237. /*********************************************************************
  238.       VARIABLE
  239.       This is the variables structure. Variables are kept in linked
  240.       list - Each gui file has a pointer to such a list for its own
  241.       private vars. the Global vars pointer is kept in the GCmain struct.
  242. **********************************************************************/
  243.  
  244. struct var
  245.    char *name;          // the variable's name (AllocVec)
  246.    char *str;           // the variable's contents (AllocVec)
  247.    struct var *next;    // ptr to next variable in list
  248.    APTR ex;        // for future expansion (NULL now)
  249. };
  250.  
  251. /*********************************************************************
  252.       CYCLER & RADIO GADGETS
  253.       This structure holds the fields of a cycler or a radio button
  254.       gadget. A pointer to it is kept from the event structure. 
  255. **********************************************************************/
  256.  
  257. struct cycler
  258.   char *cyp[13];   // Pointers to cycler/radio strings
  259.   char *var[13];   // Pointers to value to put in $variable
  260.   int  cno;        // Number of strings actually declared (12 max)
  261.   int  height;     // distance between radio buttons (N/A for cyclers)
  262. }; 
  263.  
  264. /*********************************************************************
  265.       EVENT COMMAND
  266.       This structure holds an event command. They are linked in
  267.       a list with a pointer to the top event command kept in the
  268.       event structure.
  269. **********************************************************************/
  270.  
  271. struct line
  272. {
  273.   SHORT  type;                         // type of command (see Gui4Cli.def)
  274.   int    progline;                     // line No of the command in the file
  275.   union  commandunion arg[OPT_COUNT];  // the command's arguments
  276.   struct line *next;                   // pointer to next command or NULL
  277.   // -------- private fields below
  278. };
  279.  
  280. /*********************************************************************
  281.       EVENT
  282.       This is the main event structure. Events are linked in a list
  283.       with a pointer to the top event kept in the guifile structure.
  284. **********************************************************************/
  285.  
  286. struct Event
  287. {
  288.   union commandunion arg[OPT_COUNT];    // the event's arguments (LTWH etc)
  289.   int ID;                // gadget's internal id - only for Gui4Cli
  290.   int UID;               // GADID of gadget (or 0 if not defined)
  291.   int key;               // Decimal value of Keyboard shortcut
  292.   LONG  val;             // current value of gadget (varies..)
  293.   SHORT type;            // type of gadget (see file Gui4Cli.def)
  294.   char  *file;           // pointer to the event's variable name
  295.   BOOL  onoff;           // 0=gadget is ON, 1=OFF
  296.   LONG progline;         // Line in the file where event is declared
  297.   LONG lastline;         // Line No of last of this events commands
  298.   BOOL  appear;          // whether it appears or not (SHOW|HIDE)
  299.   int   l, t, w, h;      // current ACTUAL (full window) left top width height
  300.   struct guifile *gf;    // pointer to the guifile of this event
  301.   struct Gadget *gad;       // Pointer to the gadget struct - If it's a gadget
  302.   struct DiskObject *dobj;  // Pointer to icon for AppIcons & icons
  303.   struct cycler *cy;        // pointer to cycler struct - also cast into general purpose pointers
  304.   struct fulist *lt;     // pointer to struct if it's a ListView (or NULL)
  305.   struct TextAttr *fta;  // text attribute struct
  306.   struct TextFont *ftf;  // text font struct
  307.   UBYTE  *help;          // pointer to help text or NULL
  308.   struct line *topx;     // first of a linked list of event commands
  309.   struct var *topvar;    // first of list of this event's variables (if defined)
  310.   struct Event *next;   // next in the list of events
  311.   // --------- private fields below here
  312. };
  313.  
  314.  
  315. /*********************************************************************
  316.       GUI FILE
  317.       This is the main guifile structure. Guis are linked in a list
  318.       with a pointer to the first gui kept in the G4C structure.
  319. **********************************************************************/
  320.  
  321. struct guifile
  322.   LONG   magic;                 // for sanity checks - must be 7225825
  323.   struct Window   *wn;          // pointer to this gui's window (if open)
  324.   struct Screen   *sc;          // ptr to screen (if window's open)
  325.   struct AppMenuItem *appitem;  // ptr to appitem (if any)
  326.   struct Menu *menu;            // menus (if any)
  327.   struct TextAttr *fta;         // text attributes
  328.   struct TextFont *ftf;         // text font
  329.   BPTR cp;                      // console pointer for this gui (if any)
  330.   char scr[31];                 // buffer for screen name
  331.   char imgname[35];             // name of background image (if any)
  332.   char *wntitle;                // ptr to window's title
  333.   char *wow;                    // pointer to win-on-win gui name
  334.   int  wowl, wowt;              // offsets for winonwin
  335.   char fullpath[140];           // full path & filename of gui file
  336.   char name[35];                // just the filename (separate for guirename)
  337.   UWORD wnsmall[4];             // small window sizes LTWH
  338.   char   *path;                 // variable search path
  339.   BOOL   usepath;               // 1=use path, 0=use global (forget it..)
  340.   struct Event *topbt;         // first of list of EVENTs
  341.   struct var *topvar;           // first of list of this gui's variables
  342.   struct guifile *next;         // next gui file
  343.   // ------------- private fields below
  344. };
  345.  
  346. /*********************************************************************
  347.     MAIN Gui4CLi STRUCTURE
  348.    !!! This is the structure you receive in the msg->gcmain field !!!
  349.    It's main use is to get a pointers to the top gui file (from where
  350.    you can see all events and all commands), or to the current lv
  351.    or to the Global variable list etc...
  352. **********************************************************************/
  353.  
  354. struct GCmain
  355. {  
  356.    LONG magic;                   // sanity check  (MM_G4C = 4848484)
  357.  
  358.    struct guifile *topguifile;   // first of a linked list of gui files
  359.    struct Event *curbt;          // current event pointer (for local vars etc)
  360.    struct Event *curgad;     // GAD - current gadget pointer (for info)
  361.    struct guifile *curgf;        // GUI - current gui pointer
  362.    struct fulist *curlv;         // LV  - current listview pointer
  363.    struct var *gtopvar;          // linked list of Global variables
  364.    struct imginfo *topimage;     // top of linked list of images
  365.  
  366.    LONG tab;                     // tabsize
  367.    char *pipebuff;               // pointer to pipe buffer
  368.    LONG grid;                    // grid size for visual edit def=1
  369.    LONG maxtransloop;            // set to 100 - how many times translate can retranslate the buffer before error
  370.    UBYTE  defscreenname[40];     // default screen name (* = front screen)
  371.  
  372.    // general purpose memory buffers (you can use them for temporary storage)
  373.    char *membuff[5];        // 5 main memory buffers of buffsize length
  374.    LONG buffsize;        // size of buffers
  375.  
  376.    // These are available for use.. (used internally as flags etc)
  377.    LONG num;                            // SPARE LONG
  378.    char buff[256];                      // SPARE BUFFER
  379.    char *pt, *pt2;                      // SPARE CHARACTER POINTERs
  380.    __aligned struct FileInfoBlock fib;  // SPARE fib
  381.    __aligned BPTR lk;                   // SPARE BPTR
  382.  
  383.    // for internal variables
  384.    LONG   src_pos;                      // position for searchvar
  385.    LONG   src_length;                   // var length for searchvar
  386.    USHORT red, green, blue;             // Last Palette's RGB values
  387.    LONG   color, totcolors;             // + color number + No of colors
  388.    struct imginfo *curimg;              // current image
  389.    LONG   mx, my;                       // mouse position
  390.  
  391.    // holding place for the default font (MONOspace)
  392.    struct TextAttr __aligned ta;        // our txtattr for the MONO font
  393.    UBYTE  fontbuff[40];                 // buffer for font name
  394.  
  395.    // ------------------ private fields below..
  396.  
  397. };
  398.  
  399. /*********************************************************************
  400.     Magic numbers
  401.     Some of these are used to check the "sanity" of    Gui4Cli, 
  402.     and others to identify where messages are comming from.
  403. **********************************************************************/
  404.  
  405. #define MM_PIPE_LAUNCH    6511841 // pipe launch identifier
  406. #define MM_PIPE_DATA    4523666 // pipe data identifier
  407. #define MM_PIPE_RDV     4526789    // magic for pipe rendez-vous struct
  408. #define MM_LAUNCH    7250838 // launch message identifier
  409. #define MM_GFILE    7225825    // gui file sanity check
  410. #define MM_C_GUI    7226625 // c:gui identifier
  411. #define MM_LISTVIEW     22108   // lv sanity check
  412. #define MM_G4C          4848484    // gcmain struct's sanity check
  413. #define MM_OUTSIDER     392001  // the g4cmsg message identifier
  414.  
  415.  
  416.  
  417.  
  418.